package com.mp3s.plugin_quote;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class Download {

    public static String url = "http://hq.sinajs.cn/list=";
    public static String param = "https://finance.sina.com.cn";

    public static String down(String code) {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpGet request = new HttpGet(url+code);
            request.addHeader("Accept", "application/json");
            request.addHeader("Referer", param);

            try (CloseableHttpResponse response = httpClient.execute(request)) {
                String responseBody = EntityUtils.toString(response.getEntity());
                // System.out.println(responseBody);
                return responseBody;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}